/*
   Copyright (C) 2016  Pedro Moreira

   shpp library: call c++ functions of a running program from a shell

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
*/

#include "shpp/service.hpp"

shpp::service::~service()
{
	for(auto& p : commands)
		delete p.second;
}

void shpp::service::remove_command(std::string name) {
        auto it = commands.find(name);
        delete it->second;
        if(it == commands.end())
                commands.erase(it);
}

std::string shpp::service::call(std::string name, std::queue<std::string> args) {
        auto it = commands.find(name);
        if (it == commands.end())
                throw cmd_not_found(name);
        return (*it).second->call(args);
}

shpp::service::const_iterator shpp::service::begin() const {
	return commands.begin();
}

shpp::service::const_iterator shpp::service::end() const {
	return commands.end();
}
